#!/bin/bash
# 动态配置生成器

NODES=${1:-6}
HOST_PREFIX=${2:-"localhost"}
PORT_BASE=${3:-11000}
OUTPUT_FILE=${4:-"etc/conf.json"}

echo "生成配置: N=$NODES, Host=$HOST_PREFIX, Port=$PORT_BASE"

cat > $OUTPUT_FILE << JSON
{
   "maxBatchSize": 30000,
   "maxTxSize": 250,
   "sleepTimer": 50,
   "clientTimer": 10000,
   "broadcastTimer": 10000,
   "tParameter": 0,
   "verbose": true,
   "evalMode": 0,
   "evalInterval" : 10,
   "cryptoOpt": 0,
   "local": true,
   "maliciousNode": true,
   "maliciousMode": 0,
   "maliciousNID": "1,2",
   "splitPorts": false,
   "logOpt": 0,
   "consensus" : 14,
   "RBCType" : 1,
   "replicas": [
JSON

for i in $(seq 0 $((NODES-1))); do
    port=$((PORT_BASE + i))
    echo "      {" >> $OUTPUT_FILE
    echo "         \"id\": \"$i\"," >> $OUTPUT_FILE
    echo "         \"host\": \"$HOST_PREFIX\"," >> $OUTPUT_FILE
    echo "         \"port\": \"$port\"" >> $OUTPUT_FILE
    if [ $i -lt $((NODES-1)) ]; then
        echo "      }," >> $OUTPUT_FILE
    else
        echo "      }" >> $OUTPUT_FILE
    fi
done

echo "   ]" >> $OUTPUT_FILE
echo "}" >> $OUTPUT_FILE

echo "配置已生成: $OUTPUT_FILE"
